{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form gg-form-bar border-t border-x">

    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="name" placeholder="客户编码/客户名称/员工/单号" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <select name="mType" >
            <option value="">类型</option>
            {foreach ['','收入','支出']  as $key=>  $v}
            <option value="{$key}">{$v}</option>
            {/foreach}
        </select>
    </div>
    <div class="layui-input-inline" style="width:300px;">
        <select name="orderType" >
            <option value="">单据类型</option>
            {foreach ['','销售收款单','销售退货单','采购付款单','','费用报销单']  as $key=>  $v}
            <option value="{$key}">{$v}</option>
            {/foreach}
        </select>
    </div>

    <div class="layui-input-inline" style="width:300px;">
        <input type="text" name="orderDate" placeholder="单据日期" readonly id="orderDate" class="layui-input" autocomplete="off" />
    </div>
    <div class="layui-input-inline" style="width:150px;">
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
        <button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
    </div>
</form>
<div class="p-3">
    <div>
        <table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
<!--        <button class="layui-btn layui-btn-sm" lay-event="add">+ 添加承兑</button>-->
<!--        <button class="layui-btn layui-btn-sm layui-btn-danger " lay-event="dels" type="button">删除</button>-->
<!--        <button class="layui-btn layui-btn-sm layui-btn-normal " lay-event="onUse" type="button">批量使用</button>-->
<!--        <button class="layui-btn layui-btn-sm layui-btn-warm " lay-event="onBack" type="button">批量撤回</button>-->
    </div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    const moduleInit = ['tool'];

    let mType=['','收入','支出'];
    let orderType=['','销售收款','销售退款','采购付款','','费用报销'];
    function gouguInit() {
        var treeTable = layui.treeTable, tool = layui.tool;
        var form =layui.form;
        layui.laydate.render({
            elem:"#orderDate",
            range:'~'
        })
        var tableIns = treeTable.render({
            elem: '#treeTable'
            , url: "index"
                ,toolbar: '#toolbarDemo'
            , tree: { // treeTable 特定属性集
                customName: {name: 'name'},
                data: {},
                view: {showIcon: false},
                async: {},
                callback: {}
            }
            // ,defaultToolbar:  ['filter',  'exports']
            , cellMinWidth: 80
            , cols: [[
                {type: 'checkbox', fixed: 'left' },
                {fixed: 'left',field: 'id',title: 'ID' ,unresize: true,hide:true},
                , {field: 'years', title: '年份'}
                , {field: 'userName', title: '姓名'}
                , {field: 'positionName', title: '职位'}
                , {field: 'jan', title: '1月'}
                , {field: 'feb', title: '2月'}
                , {field: 'mar', title: '3月'}
                , {field: 'apr', title: '4月'}
                , {field: 'may', title: '5月'}
                , {field: 'jun', title: '6月'}
                , {field: 'jul', title: '7月'}
                , {field: 'aug', title: '8月'}
                , {field: 'sep', title: '9月'}
                , {field: 'oct', title: '10月'}
                , {field: 'nov', title: '11月'}
                , {field: 'dec', title: '12月'}
                , {field: 'dTargets', title: '年度目标'}
                , {field: 'overed', title: '实际完成'}
                , {field: 'overedl', title: '完成率'}
                , {field: 'ndjx', title: '年度绩效'}
                , {field: 'nzjx', title: '年终绩效'}
                , {field: 'gljt', title: '管理津贴'}

            ]]
            , page: false
        });
        //表头工具栏事件
        $('.add-menu').on('click', function () {
            tool.side("add");
            return;
        });
        form.on('submit(webform)', function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });
        //操作按钮
        treeTable.on('tool(treeTable)', function (obj) {
            console.log(obj);
            if (obj.event === 'add') {
                tool.side('add?pid=' + obj.data.id);
                return;
            }
            if (obj.event === 'edit') {
                tool.side('add?id=' + obj.data.id);
                return;
            }
            if (obj.event === 'del') {
                layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                    let callback = function (e) {
                        layer.msg(e.msg);
                        if (e.code == 0) {
                            obj.del();
                        }
                    }
                    tool.delete("delete", {id: obj.data.id}, callback);
                    layer.close(index);
                });
            }
        });
        treeTable.on('toolbar(treeTable)', function(obj){
            var checkStatus = treeTable.checkStatus(obj.config.id);
            console.log(checkStatus)
            switch(obj.event){
                case 'add':
                    tool.side("{:url('add')}");
                    break;
                case 'dels':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                            let callback = function (e) {
                                layer.msg(e.msg);
                                if (e.code == 0) {
                                    tableIns.reload();
                                }
                            }
                            tool.delete("{:url('delete')}", {id: ids.join(',')}, callback);
                            layer.close(index);
                        });

                    }else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'onUse':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要使用吗?', {icon: 3, title: '提示'}, function (index) {
                            let callback = function (e) {
                                if (e.code == 0) {
                                    tableIns.reload();
                                }
                            }
                            httpRequest("{:url('onUse')}", {id: ids.join(',')}, callback);
                            layer.close(index);
                        });

                    }else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'onBack':
                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })
                        layer.confirm('确定要撤回吗?', {icon: 3, title: '提示'}, function (index) {
                            let callback = function (e) {
                                if (e.code == 0) {
                                    tableIns.reload();
                                }
                            }
                            httpRequest("{:url('onBack')}", {id: ids.join(',')}, callback);
                            layer.close(index);
                        });

                    }else {
                        layer.msg('请选择数据');
                    }

                    break;
                case 'import':

                    break;
                case 'plqr':

                    var data = checkStatus.data;
                    var ids=[]
                    if (data.length){
                        data.forEach(function (value,index) {
                            console.log('value',value)
                            ids.push(value.id)
                        })
                        $.ajax({
                            url:"{:url('onSure')}",
                            type:'post',
                            dataType:'json',
                            data:{id:ids.join(',')},
                            success:function (res) {
                                console.log('res',res)
                                layer.msg(res.msg)
                                if (res.code == 0) {
                                }
                            },
                            error(e){
                                layer.msg('网络错误，请稍后重试')
                            }
                        })
                    }else {
                        layer.msg('请选择数据');
                    }
                    break;
            };
        })
    }
</script>
{/block}
<!-- /脚本 -->